import os.path

import requests
save_dir = 'C:\\Users\\Administrator\\Desktop\\图片'
url='https://image.baidu.com/search/acjson?tn=resultjson_com&logid=8514057939567066777&ipn=rj&ct=201326592&is=&fp=result&fr=ala&word=%E5%8A%A8%E6%BC%AB%E5%9B%BE%E7%89%87&queryWord=%E5%8A%A8%E6%BC%AB%E5%9B%BE%E7%89%87&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=&ic=&hd=&latest=&copyright=&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=&expermode=&nojc=&isAsync=&pn=60&rn=30&gsm=3c&1710232814860='
header={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"}
resp=requests.get(url=url,headers=header)
img=resp.json().get('data')[5].get('hoverURL')
filename='{}.jpg'.format(img)
save_path=os.path.join(save_dir,filename)
if not os.path.exists(save_dir):
    os.makedirs(save_dir)
else:
    print('已经存在')
    os.rmdir(save_dir)

response = requests.get(url, stream=True)
response=response.content
folder_path=os.path.join(save_path,response)

# a=download_image(img)
# print(a)
# resp=requests.get(url=img)
# print(resp.content)




